var Headline = function () {

    var messageNumberToShow = 0;

    var messages = [
        "Message 1",
        "Message 2",
        "Message 3",
        "Message 4",
        "Message 5"
    ];

    var execHeadlineDetailAnimation = function (headlineDetail) {
        $("div.headlines div").fadeOut(2000, function () {
            $("div.headlines div").html(headlineDetail);
            $("div.headlines div").fadeIn(2000, function (){});
        });
    };

    var updateHeadlinesDetail = function () {
        execHeadlineDetailAnimation(messages[messageNumberToShow]);
        if (messageNumberToShow < (messages.length - 1)) {
            messageNumberToShow++;
        } else {
            messageNumberToShow = 0;
        }
    };

    this.startHeadlinesUpdateProcess = function () {
        $(document).everyTime(10000, function () {
            updateHeadlinesDetail();
        });
    };

}

function QuoteManager () {

    var quoteNumberToShow = 0;

    var quotes = [
        "\"Innovation distinguishes between a leader and a follower\". <strong>Steve Jobs</strong>.",
        "\"Adding manpower to a late software project makes it later!\". <strong>Brooks Law</strong>.",
        "\"Good programmers write code that humans can understand\". <strong>Martin Fowler</strong>.",
        "\"Testing can be used to show the presence of bugs, but never to show their absence!\". <strong>Edsger Dijkstra</strong>.",
        "\"Before software can be reusable it first has to be usable\". <strong>Ralph Johnson</strong>.",
        "\"There are two ways to write error-free programs; only the third one works.\". <strong>Alan J. Perlis</strong>."
    ];

    var execQuoteDetailAnimation = function (quoteDetail) {
        $("#quoteArea").fadeOut(2000, function () {
            $("#quoteArea").html(quoteDetail);
            $("#quoteArea").fadeIn(2000, function (){});
        });
    };

    var updateQuotesDetail = function () {
        execQuoteDetailAnimation(quotes[quoteNumberToShow]);
        if (quoteNumberToShow < (quotes.length - 1)) {
            quoteNumberToShow++;
        } else {
            quoteNumberToShow = 0;
        }
    };

    this.startQuotesUpdateProcess = function () {
        $(document).everyTime(10000, function () {
            updateQuotesDetail();
        });
    };

}

function ContentManager () {

    var requestLinkToArea = function (contentId, link, elementId) {
        $.ajax({
            type: "POST",
            url: link,
            success: function(response) {
                $("#"+elementId).html(response);
                var topMenuManager = new TopMenuManager();
                topMenuManager.activateMenuOption(contentId+"Link");
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("An Error has occurred. Please, try again later.");
            }
        });
    };

    this.loadContent = function (contentId) {
        if (contentId == "index.php") {
            document.location.href = "index.php";
        } else {
            requestLinkToArea (contentId, contentId+".php", "contentArea");
        }
    };

}

function TopMenuManager () {

    this.activateMenuOption = function (linkId) {
        deactivateMenuOptions();
        $("#"+linkId).addClass("active");
    };

    var deactivateMenuOptions = function () {
        $("ul.topMainMenu > li > a").removeClass("active");
    };

}